<?php
namespace Admin\Controller;
//use Think\Controller;
class DepartmentController extends CommontController {
    //部门添加完成
	public function add(){
        $departmentModel=D('Department');
        //系别分类添加实现
        if(IS_POST){
            if($departmentModel->create()){
                if($departmentModel->add()){
                    $this->success("添加成功",U("Department/index"));die;
                }else{
                    $this->error("添加失败");
                }
            }else{
                $this->error($departmentModel->getError());
            }
        }
        //渲染模板
        $this->display();
    }
    //部门列表完成
    public function index(){
        $departmentModel=D('Department');
        $list=$departmentModel->select();
        $this->assign('list',$list);
        $this->display();
    }
    //部门修改完成
    public function upd(){
        //实例化部门信息类模型
        $departmentModel=D('Department');
        //部门数据回显
        $de_id=I('get.de_id');
        $data=$departmentModel->find($de_id);
        $this->assign('data',$data);
        //部门信息修改
            if(IS_POST){
                if($departmentModel->create()){
                    if($departmentModel->save()!==false){
                        $this->success("修改成功",U('Department/index'));die;
                    }else{
                        $this->error("修改失败");
                    }
                }else{
                    $this->error($departmentModel->getError());
                }
            }
        //渲染模板
        $this->display();
    }
    //部门删除完成
    public function del(){
        //实例化部门信息类模型
        $departmentModel=D('Department');
        //部门数据回显
        $de_id=I('get.de_id');
        $data=$departmentModel->delete($de_id);
        if($data){
            $this->success("删除成功",U('Department/index'));die;
        }else{
            $this->error("删除失败");
        }
    }
}